// 2025/9/16
// 长度最小的子数组

class Solution {
public:
    int minSubArrayLen(int target, vector<int>& nums) {
        int n = nums.size(), ans = n + 1, count = 0;
        for(int l = 0, r = 0; r < n; r++)
        {
            count += nums[r];
            while(count >= target)
            {
                ans = min(ans, r - l + 1);
                count -= nums[l++];
            }
        }
        return ans == n + 1 ? 0 : ans;
    }
};